<?php 

require_once('functions/session.php');
require_once('functions/functions.php');

$cur_page = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
if($_SERVER['REQUEST_METHOD'] == "POST") {
	if ((isset($_POST['login_username'])) && (isset($_POST['login_password'])))
		if (user_login($_POST['login_username'], $_POST['login_password']) == false)
			$login_error = 'Incorrect. Try again!';
}
//var_dump($_SESSION);

?>

<html>

<head>
	<title>Try-On Eyewear</title>
	<link rel=stylesheet href='style.css' type='text/css' media=screen>
	<script type="text/javascript">
		function onEnter( evt, frm ) {
			var keyCode = null;
	
			if( evt.which ) {
				keyCode = evt.which;
			} 
			else if( evt.keyCode ) {
				keyCode = evt.keyCode;
			}
			if( 13 == keyCode ) {
				frm.submit();
				return false;
			}
			return true;
		}
	</script>

</head>

<body>

<div id="main">

<div id="logo"><h1><a href="index.php">Try-On Eyewear</a></h1></div>

<div id="login_status">

<?php 

if ($cur_page != 'sign_up.php') {

	if (isset($_SESSION['username']))
	 	echo '
			Logged in as <a href="">'.$_SESSION['username'].'</a> | <a href="logout.php">Logout</a>';
	else
		echo '
			<form id="login_form" name="login_form" action="'.$cur_page.'" method="POST">
				<input type="text" name="login_username" id="login_username" onkeypress="return onEnter(event,this.form);" />
				<input type="password" name="login_password" id="login_password" onkeypress="return onEnter(event,this.form);" /> 
				<input type="checkbox" name="remember_me" value="remember_me" checked /> Remember me
				<a href="sign_up.php">Sign up</a>
			</form><div class="error"">'.$login_error.'</div>'; 	
	
}
?>	
</div>

<div id="content" class="box">